﻿using BCCommon;
using BCCommon.OAEnums.WorkflowActive;
using BCDto.OA.WorkflowActive.WorkflowActive;
using BCDto.OA.WorkflowActive.WorkflowActivity;
using BCDto.OA.WorkflowActive.WorkflowActivityOperation;
using BCDto.OA.WorkflowActive.WorkflowActivityStep;
using BCDto.OA.WorkflowActive.WorkflowActivityStepFormConfig;
using BCDto.OA.WorkflowActive.WorkflowActivityStepSpecificFormItem;
using BCDto.OA.WorkflowTemplate.WorkflowTemplate;
using BCDto.OA.WorkflowTemplate.WorkflowTemplateStepButtonConfig;
using BCDto.Sim.Admin.Admin;
using BCDto.Website.User;
using BCEntity.OA.WorkflowActive.WorkflowActive;
using BCEntity.OA.WorkflowActive.WorkflowActivity;
using System;
using System.Collections.Generic;

namespace BCWorkflowEngine
{
    /// <summary>
    /// 工作流引擎
    /// </summary>
    public interface IWorkflowEngine
    {
        /// <summary>
        /// 初始化工作流活动实例
        /// </summary>
        /// <param name="workflowTemplateDto">工作流模板信息</param>
        /// <param name="adminDto">人员信息</param>
        /// <param name="userDto">用户信息</param>
        /// <returns>返回实例Id</returns>
        WorkflowActivityEntity InitWorkflowActivityInstance(WorkflowTemplateDto workflowTemplateDto,AdminDto adminDto, UserDto userDto);
        /// <summary>
        /// 提交工作流活动步骤表单
        /// </summary>
        /// <param name="fromConfigRequestDtos">工作流活动步骤表单列表</param>
        /// <param name="adminDto">人员信息</param>
        /// <param name="userDto">用户信息</param>
        /// <returns></returns>
        List<WorkflowActivityStepFormConfigDto> SubmitWorkflowActivityStepForm(List<WorkflowActivityStepFormConfigRequestDto> fromConfigRequestDtos, AdminDto adminDto, UserDto userDto);
        /// <summary>
        /// 工作流活动步骤执行操作
        /// </summary>
        /// <param name="workflowActivityOperationRequestDto">工作流活动步骤执行操作</param>
        /// <returns></returns>
        WorkflowActivityDto Execution(WorkflowActivityOperationRequestDto workflowActivityOperationRequestDto);
        /// <summary>
        /// 更新工作流活动步骤状态为已激活
        /// </summary>
        /// <param name="putDto">工作流活动步骤信息</param>
        /// <param name="adminDto">员工信息</param>
        /// <param name="userDto">用户信息</param>
        WorkflowActivityStepDto UpdateStepStatusToActivity(WorkflowActivityStepPutDto putDto, AdminDto adminDto, UserDto userDto);
        /// <summary>
        /// 更新工作流活动步骤状态为已完成
        /// </summary>
        /// <param name="putDto">工作流活动步骤信息</param>
        WorkflowActivityStepDto UpdateStepStatusToComplete(WorkflowActivityStepPutDto putDto);
        /// <summary>
        /// 修改工作流活动步骤按钮显示条件
        /// </summary>
        /// <param name="putDto">工作流活动步骤按钮显示条件信息</param>
        /// <returns></returns>
        WorkflowActivityStepDto UpdateStepButtonShowCondition(WorkflowActivityStepButtonConditionPutDto putDto);
        /// <summary>
        /// 获取工作流活动信息
        /// </summary>
        /// <param name="workflowActivityId">工作流活动Id</param>
        /// <returns></returns>
        WorkflowActivityDto GetEntity(long workflowActivityId);
        /// <summary>
        /// 获取工作流活动步骤列表
        /// </summary>
        /// <param name="workflowActivityId">工作流活动Id</param>
        /// <returns></returns>
        IEnumerable<WorkflowActivityStepDto> GetActivityStepList(long workflowActivityId);
        /// <summary>
        /// 获取工作流活动步骤表单列表
        /// </summary>
        /// <param name="workflowActivityId">工作流活动Id</param>
        /// <returns></returns>
        IEnumerable<WorkflowActivityStepFormConfigDto> GetActivityStepFormConfigList(long workflowActivityId);
        /// <summary>
        /// 获取工作流活动步骤按钮列表
        /// </summary>
        /// <param name="templateStepCode">工作流模板步骤Code</param>
        /// <returns></returns>
        IEnumerable<WorkflowTemplateStepButtonConfigDto> GetActivityStepButtonList(string templateStepCode);
        /// <summary>
        /// 获取工作流步骤为条件步骤的活动中列表
        /// </summary>
        /// <returns></returns>
        IEnumerable<WorkflowActivityStepDto> GetWorkflowStepConditionStatusActiveList();

        /// <summary>
        /// 获取工作流活动分页列表(待处理任务)
        /// </summary>
        /// <param name="adminId">员工Id</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        PageableList<WorkflowActivityViewDto> PendingHandleTaskQuery(long adminId, DateTime? start, DateTime? end, string sortName, bool? ascending, int pageIndex, int pageSize);
        /// <summary>
        /// 获取工作流活动分页列表（我发起的，已完成的，已关闭的）
        /// </summary>
        /// <param name="adminId">员工Id</param>
        /// <param name="userId">其他用户Id</param>
        /// <param name="activityStatus">活动状态</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        PageableList<WorkflowActivityDto> Query(long? adminId, long? userId, OAActivityStatus? activityStatus, DateTime? start, DateTime? end, string sortName, bool? ascending, int pageIndex, int pageSize);

        /// <summary>
        /// 获取工作流特殊表单已审批完成待处理实例
        /// </summary>
        /// <returns></returns>
        IDictionary<long, string> GetWorkflowActivityStepSpecificFormDone();

        /// <summary>
        /// 获取工作流活动步骤特殊表单项
        /// </summary>
        /// <param name="workflowActivityId">工作流活动Id</param>
        /// <returns></returns>
        IEnumerable<WorkflowActivityStepSpecificFormItemDto> GetActivityStepSpecificFormItemList(long workflowActivityId);

        /// <summary>
        /// 修改工作流状态为已完成
        /// </summary>
        /// <param name="workflowActivityId">工作流活动Id</param>
        /// <returns></returns>
        WorkflowActivityDto UpdateActivityStatusToDone(long workflowActivityId);
        
        /// <summary>
        /// 特殊表单数据写入对应表
        /// </summary>
        /// <param name="tableName">表名称</param>
        /// <param name="keyValuePairs">对应字段及值</param>
        /// <returns></returns>
        long InsertSpecificFormTable(string tableName, Dictionary<string, string> keyValuePairs);

        /// <summary>
        /// 更新特殊表单数据处理已执行
        /// </summary>
        /// <param name="workflowActivityId">工作流活动Id</param>
        /// <param name="tableName">表名称</param>
        /// <param name="formConfigRows">表单行号</param>
        /// <param name="formItemRows">表单项行号</param>
        void UpdateSpecificFormIsExecution(long workflowActivityId, string tableName, int? formConfigRows, int? formItemRows);

        /// <summary>
        /// 特殊表单数据更新对应表
        /// </summary>
        /// <param name="tableName">表名称</param>
        /// <param name="keyValuePairs">更新对应字段及值</param>
        /// <param name="updateKeyValuePairs">检索键对应字段及值</param>
        void UpdateSpecificFormTable(string tableName, Dictionary<string, string> keyValuePairs, Dictionary<string, string> updateKeyValuePairs);
    }
}
